package com.zkld.frame.service.impl;

import com.zkld.frame.dto.ResponseDTO;
import com.zkld.frame.entitys.Graphical;
import com.zkld.frame.example.GraphicalExample;
import com.zkld.frame.mapper.GraphicalMapper;
import com.zkld.frame.service.GraphicalService;
import com.zkld.frame.util.ResponseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GraphicalServiceImpl implements GraphicalService {

    @Autowired
    GraphicalMapper graphicalMapper;

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public ResponseDTO saveGraphical(Graphical graphical) {
        graphicalMapper.insert(graphical);
        return ResponseFactory.getResponse(null,"success");
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public ResponseDTO getGraphicalInfoByUserId(String userId) {
        GraphicalExample graphicalExample = new GraphicalExample();
        graphicalExample.createCriteria().andUserIdEqualTo(Integer.valueOf(userId));
        return ResponseFactory.getResponse(graphicalMapper.selectByExample(graphicalExample),"success");
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public ResponseDTO update(Graphical graphical) {
        graphicalMapper.updateNodesInfoByPrimaryKey(graphical.getId(),graphical.getNodes());
        return ResponseFactory.getResponse(null,"success");
    }

}
